package com.jobmanagementsystem.controller;

import com.jobmanagementsystem.common.CommonResult;
import com.jobmanagementsystem.entity.EmploymentInfo;
import com.jobmanagementsystem.feign.ManagementServiceFeign;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping(value = "/employmentManagement",name = "就业")
public class EmploymentInfoController {

  @Autowired
  private ManagementServiceFeign managementServiceFeign;

  @GetMapping(value = "/index")
  public ModelAndView index() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("system/employmentinfo/employmentinfo");
    return modelAndView;
  }

  @GetMapping(value = "/managementInfo")
  public ModelAndView managementInfo() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("system/employmentinfo/employmentinfo");
    return modelAndView;
  }

  @GetMapping("/statistic")
  public ModelAndView statistic() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("system/employmentstatistic/employmentstatistic");
    return modelAndView;
  }

  @PostMapping(value = "/getEmploymentList",name = "列表")
  public CommonResult<List<EmploymentInfo>> getAllInfo(EmploymentInfo employmentInfo,
      @RequestParam("limit") int pageSize, @RequestParam("page") int pageNum) {
    return managementServiceFeign
        .getAllInfo(employmentInfo, pageSize, pageNum);
  }

  @PostMapping(value = "/getEmploymentInfo",name = "详情")
  public CommonResult<List<EmploymentInfo>> getEmploymentInfo(EmploymentInfo info,
      @RequestParam("limit") int pageSize, @RequestParam("page") int pageNum) {

    return managementServiceFeign
        .getEmploymentInfo(info, pageSize, pageNum);
  }

  @PostMapping(value = "/addEmploymentInfo",name = "新增")
  public CommonResult<Integer> addEmploymentInfo(EmploymentInfo info) {
    managementServiceFeign.addEmploymentInfo(info);
    return CommonResult.generateSuccessResult(1, 1);
  }

  @PostMapping(value = "/updateEmploymentInfo",name = "修改")
  public CommonResult<Integer> updateEmploymentInfo(EmploymentInfo info) {
    managementServiceFeign.updateEmploymentInfo(info);
    return CommonResult.generateSuccessResult(1, 1);
  }

  @PostMapping(value = "/delEmployment/{infoId}",name = "删除")
  public CommonResult<Integer> delInfo(@PathVariable("infoId") String infoId) {
    managementServiceFeign.delInfo(infoId);
    return CommonResult.generateSuccessResult(1, 1);
  }

  @PostMapping(value = "/statistic/{fieldName}",name = "统计")
  public CommonResult<List<Map<String, String>>> getStatisticData(
      @PathVariable("fieldName") String fieldName,
      @RequestParam("limit") int pageSize, @RequestParam("page") int pageNum) {
    return managementServiceFeign
        .getStatisticData(fieldName, pageSize, pageNum);
  }

}
